polynomial Derived Type

type, public :: polynomial

Defines a polynomial, and associated routines for performing polynomial operations.


Constructor

public interface polynomial

  • private function poly_init_1(order) result(rst)

    Initializes a new polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 0).

    Return Value type(polynomial)

    The new polynomial object.

  • private function poly_init_2(c) result(rst)

    Initializes a new polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real64), intent(in), dimension(:) :: c

    The array of polynomial coefficients. The coefficients are established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Return Value type(polynomial)

    The new polynomial object.


Type-Bound Procedures

procedure, public :: companion_mtx => poly_companion_mtx

  • private pure function poly_companion_mtx(this) result(c)

    Returns the companion matrix for the polynomial.

    See Also

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value real(kind=real64), dimension(this%order(), this%order())

    The companion matrix.

procedure, public :: divide => poly_divide

  • private pure subroutine poly_divide(numerator, divisor, quotient, remainder)

    Divides one polynomial by another and returns the quotient and remainder.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: numerator

    The numerator polynomial.

    class(polynomial), intent(in) :: divisor

    The denominator polynomial.

    type(polynomial), intent(out) :: quotient

    The quotient polynomial.

    type(polynomial), intent(out) :: remainder

    The remainder polynomial.

generic, public :: evaluate => evaluate_real, evaluate_complex

  • private pure elemental function poly_eval_double(this, x) result(y)

    Evaluates a polynomial at the specified points.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    real(kind=real64), intent(in) :: x

    The value(s) at which to evaluate the polynomial.

    Return Value real(kind=real64)

    The value(s) of the polynomial at x.

  • private pure elemental function poly_eval_complex(this, x) result(y)

    Evaluates a polynomial at the specified points.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    complex(kind=real64), intent(in) :: x

    The value(s) at which to evaluate the polynomial.

    Return Value complex(kind=real64)

    The value(s) of the polynomial at x.

procedure, public :: fit => poly_fit

  • private pure subroutine poly_fit(this, x, y, order)

    Fits a polynomial of the specified order to the supplied data set.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the independent variable data points. Notice, must be N > order.

    real(kind=real64), intent(inout), dimension(:) :: y

    On input, an N-element array containing the dependent variable data points. On output, the contents are overwritten.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 1).

procedure, public :: fit_thru_zero => poly_fit_thru_zero

  • private pure subroutine poly_fit_thru_zero(this, x, y, order)

    Fits a polynomial of the specified order that passes through zero to the supplied data set.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: x

    An N-element array containing the independent variable data points. Notice, must be N > order.

    real(kind=real64), intent(inout), dimension(:) :: y

    On input, an N-element array containing the dependent variable data points. On output, the contents are overwritten.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 1).

procedure, public :: get => get_poly_coefficient

  • private pure function get_poly_coefficient(this, ind) result(c)

    Gets the requested polynomial coefficient by index. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: ind

    The polynomial coefficient index.

    Return Value real(kind=real64)

    The requested coefficient.

procedure, public :: get_all => get_poly_coefficients

  • private pure function get_poly_coefficients(this) result(c)

    Gets an array containing all the coefficients of the polynomial. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value real(kind=real64), dimension(this%order() + 1)

    The array of coefficients.

generic, public :: initialize => init_poly, init_poly_coeffs

  • private pure subroutine init_poly(this, order)

    Initializes the polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: order

    The order of the polynomial (must be >= 0).

  • private pure subroutine init_poly_coeffs(this, c)

    Initializes the polynomial instance.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    real(kind=real64), intent(in), dimension(:) :: c

    The array of polynomial coefficients. The coefficients are established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

procedure, public :: order => get_poly_order

  • private pure function get_poly_order(this) result(n)

    Returns the order of the polynomial object.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value integer(kind=int32)

    The order of the polynomial. Returns -1 in the event no polynomial coefficients have been defined.

procedure, public :: roots => poly_roots

  • private pure function poly_roots(this) result(z)

    Computes all the roots of a polynomial by computing the eigenvalues of the polynomial companion matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(in) :: this

    The polynomial object.

    Return Value complex(kind=real64), allocatable, dimension(:)

    The roots of the polynomial.

procedure, public :: set => set_poly_coefficient

  • private pure subroutine set_poly_coefficient(this, ind, c)

    Sets the requested polynomial coefficient by index. The coefficient index is established as follows: c(1) + c(2) * x + c(3) * x2 + ... c(n) * xn-1.

    Arguments

    Type IntentOptional Attributes Name
    class(polynomial), intent(inout) :: this

    The polynomial object.

    integer(kind=int32), intent(in) :: ind

    The polynomial coefficient index.

    real(kind=real64), intent(in) :: c

    The polynomial coefficient.